package com.example.xss.commom.util;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.json.JSONObject;
import com.example.xss.client.LixingerClient;
import com.example.xss.commom.enums.MetricNameEnum;
import com.example.xss.lixinger.model.IndexAnalysisSource;

/**
 * 通过反射直接获取对应字段值
 */
public class AnalysisSourceBuildUtil {

    public static IndexAnalysisSource build(JSONObject data) {
        IndexAnalysisSource source = new IndexAnalysisSource();
        for (MetricNameEnum metricNameEnum : MetricNameEnum.values()) {
            ReflectUtil.setFieldValue(source, metricNameEnum.toString().toLowerCase(),
                    LixingerClient.drillValue(metricNameEnum, data));
        }
        return source;
    }
}
